package com.gome.ai.aiparter.ws.enity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.util.Strings;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 对话
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Conversation implements Serializable {
    String system;
    String[] roles;
    List<String[]> messages = new ArrayList<>();
    int offset;
    String sep_style;
    String sep;

    /**
     * 对话模板
     */
    public static final Conversation conv_v1_2 = new Conversation(
            "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.",
            new String[]{"Human", "Assistant"},
            new ArrayList<>(Arrays.asList(new String[] {"Human", "What are the key differences between renewable and non-renewable energy sources?"},
                    new String[]{"Assistant",
                            "Renewable energy sources are those that can be replenished naturally in a relatively " +
                                    "short amount of time, such as solar, wind, hydro, geothermal, and biomass. " +
                                    "Non-renewable energy sources, on the other hand, are finite and will eventually be " +
                                    "depleted, such as coal, oil, and natural gas. Here are some key differences between " +
                                    "renewable and non-renewable energy sources:\n" +
                                    "1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable " +
                                    "energy sources are finite and will eventually run out.\n" +
                                    "2. Environmental impact: Renewable energy sources have a much lower environmental impact " +
                                    "than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, " +
                                    "and other negative effects.\n" +
                                    "3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically " +
                                    "have lower operational costs than non-renewable sources.\n" +
                                    "4. Reliability: Renewable energy sources are often more reliable and can be used in more remote " +
                                    "locations than non-renewable sources.\n" +
                                    "5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different " +
                                    "situations and needs, while non-renewable sources are more rigid and inflexible.\n" +
                                    "6. Sustainability: Renewable energy sources are more sustainable over the long term, while " +
                                    "non-renewable sources are not, and their depletion can lead to economic and social instability.\n"}
            )),
            2,
            "SINGLE",
            "###"
    );

    public String getPrompt(){
        StringBuilder recordBuffer = new StringBuilder(this.getSystem());
        for (String[] item : this.getMessages()) {
            if (Strings.isBlank(item[1])) {
                recordBuffer.append("###").append(item[0]).append(":").append(item[1]);
            }
        }

        return recordBuffer.toString();
    }
}
